package com.jstower.common.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

/**
 * Description: 抽象controller，主要是为了放一些公共的变量或方法
 * Author: chenshuai
 * Project: js-webapp
 * Version: V1.0
 * Create Date: 16/3/1
 */
public class BaseController {

    protected Logger logger = LoggerFactory.getLogger(BaseController.class);
    //返回数据的通用对象
    protected AppResponse appResponse;

    /**
     * 基于@ExceptionHandler异常处理
     * @param request
     * @param ex
     * @return
     */
    @ExceptionHandler
    public String exp(HttpServletRequest request, Exception ex) {

        request.setAttribute("ex", ex);

        // 根据不同错误转向不同页面
        /*if(ex instanceof BusinessException) {
            return "error-business";
        }else if(ex instanceof ParameterException) {
            return "error-parameter";
        } else {
            return "error";
        }*/
        ex.printStackTrace();
        return null;
    }
}
